package com.xinyi.reactivemvvm.basic.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.xinyi.basic.base.fragment.BaseFragment;

/**
 * @author 杨耿雷
 * @date 2024/9/25 14:46
 * @description Fragment的ViewBinding基类
 */
public abstract class BaseViewBindingFragment<VDB extends ViewDataBinding> extends BaseFragment {

    protected VDB binding;

    @NonNull
    @Override
    public View setContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), initLayoutId(), null, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        initObserveUI();
        super.onViewCreated(view, savedInstanceState);
    }

    /**
     * 初始化UI观察
     */
    protected void initObserveUI() { }
}
